package com.carbonspark.ecoquest.infra.basic.service.impl;

import com.carbonspark.ecoquest.infra.basic.entity.TaskRules;
import com.carbonspark.ecoquest.infra.basic.mapper.TaskRulesDao;
import com.carbonspark.ecoquest.infra.basic.service.TaskRulesService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * (TaskRules)表服务实现类
 *
 * @author makejava
 * @since 2025-03-25 17:31:32
 */
@Service("taskRulesService")
public class TaskRulesServiceImpl implements TaskRulesService {
    @Resource
    private TaskRulesDao taskRulesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TaskRules queryById(Long id) {
        return this.taskRulesDao.queryById(id);
    }



    /**
     * 新增数据
     *
     * @param taskRules 实例对象
     * @return 实例对象
     */
    @Override
    public TaskRules insert(TaskRules taskRules) {
        this.taskRulesDao.insert(taskRules);
        return taskRules;
    }

    /**
     * 修改数据
     *
     * @param taskRules 实例对象
     * @return 实例对象
     */
    @Override
    public TaskRules update(TaskRules taskRules) {
        this.taskRulesDao.update(taskRules);
        return this.queryById(taskRules.getId());
    }

    @Override
    public Integer queryRulesByTaskId(Long taskId) {

        return taskRulesDao.queryRulesCount(taskId);
    }

    @Override
    public List<TaskRules> queryByTaskId(Long taskId) {
       List<TaskRules> taskRulesList =  taskRulesDao.queryAllRules(taskId);
        return taskRulesList;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.taskRulesDao.deleteById(id) > 0;
    }
}
